package utils;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDCB_CRUD {
    Connection con;
    Statement st;
    ResultSet rs;
    @Before
    public void before() throws SQLException {
        //通过工具类获取连接对象
        con = JDBCUtils.getConnction();
        //创建可执行对象
        st = con.createStatement();
    }
    @After
    public void after() {
        JDBCUtils.coloseResouces(rs,st,con);
    }
    //增删改查
    @Test
    public void findAll() throws SQLException {
         rs = st.executeQuery("select * from user ");
        while (rs.next()){
            int uid = rs.getInt(1);
            String name = rs.getString(2);
            String sex = rs.getString(3);
            double money = rs.getDouble(4);
            String address = rs.getString(5);
            System.out.println(uid + "\t" + name + "\t" + sex + "\t" + money + "\t" + address);

        }
    }
    @Test
    public void insertUser() throws SQLException {
        System.out.println(st.executeUpdate("insert into user values(4,'金莲妹妹','女',9000,'王婆家')") > 0 ? "添加成功" : "添加失败");
    }
}
